package spring.config;

import org.apache.commons.io.FileUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.IOException;

@Controller
public class UploadController {

    @PostMapping(value = "/upload")
    @ResponseBody
    public String upload(MultipartFile file) {
        try {
            System.out.println(file.getName());
            System.out.println(file.getOriginalFilename());
            FileUtils.writeByteArrayToFile(new File("/Users/tuyou/Downloads/upload/" + file.getOriginalFilename()), file.getBytes());
            return "上传成功";
        } catch (IOException e) {
            e.printStackTrace();
            return "上传失败";
        }
    }
}
